﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using Caliburn.Core.InversionOfControl;
using Caliburn.PresentationFramework.Behaviors;

namespace MTGenome.ViewModels
{
    [Validate, PerRequest(typeof(CardQuantityViewModel)), PartCreationPolicy(CreationPolicy.NonShared)]
    public sealed class CardQuantityViewModel : QuickCardViewModel
    {
        private readonly DeckViewModel _deck = null;
        private int _quantity = 1;

        public CardQuantityViewModel(DeckViewModel deck, CardDetailViewModel card)
            : base(card)
        {
            _deck = deck;
        }

        [Range(0, 4)]
        public int Quantity
        {
            get { return _quantity; }
            set
            {
                if (_quantity != value)
                {
                    _quantity = value;
                    if (_quantity == 0)
                    {
                        _deck.Cards.Remove(this);
                    }
                    else
                    {
                        _deck.CanSave = true;
                        NotifyOfPropertyChange(() => Quantity);
                    }
                }
            }
        }

        public int MultiverseID
        {
            get { return Card.MultiverseID; }
        }

        public override string Text
        {
            get { return Card == null ? string.Empty :  Quantity.ToString() + " " + Card.Name ; }
        }
    }
}
